<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <script src="js/vue.js"></script>
    <script src="js/axios.js"></script>
</head>

<body>
    <div id="app">
        <div>用户名 <input v-model="username" /></div>
        <div>密码 <input v-model="userpwd" /></div>
        <button @click="login">登录</button>
    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            username: "",
            userpwd: ""
        },
        methods: {
            async login() {

                let { data: list } = await axios({
                    method: "get",
                    url: "http://localhost:2345/userinfos",
                    params: {
                        username: this.username,
                        userpwd: this.userpwd
                    }
                })
                if (list.length) {
                    let info = list[0];
                    window.localStorage.setItem("userinfo", JSON.stringify(info));
                    let backurl = window.localStorage.getItem("backurl");
                    if (backurl) {
                        window.location.href = backurl;
                    } else {

                        window.location.href = "list.html";
                    }
                } else {
                    alert("用户名和密码不存在");
                }



            }
        }
    })

</script>

</html>